namespace RL

open Garnet.Composition
open RL.Components

module Combat =
    type CombatEngagement = { attacker : Eid; defender : Eid }

    type Container with
        member c.RegisterCombatSystem =
            c.On<CombatEngagement> <| fun r ->
                let attacker = c.Get(r.attacker)
                let defender = c.Get(r.defender)

                let defHealth = defender.Get<Health>()
                let defCombat = defender.Get<CombatStats>()
                let atkCombat = attacker.Get<CombatStats>()

                defHealth.Lose(atkCombat.damage - defCombat.defense)

    let init(c : Container) =
        Disposable.Create[c.RegisterCombatSystem] |> ignore
